<?php
/*
 * Created on 20.12.2005
 *
 */

m2import('phpinchains/Filter.php');
m2import('phpinchains/RuntimeConfig.php');
 
/**
 * Retrieves module and action from the path info for use in action dispatcher filter
 * 
 * If filter parameter 'action' is set, it will be used as action. Otherwise filter
 * parameter 'module' is needed.
 * If filter parameter 'parameter' is set, than these parameters will be added to 
 * the query parameters or will override them, respectively.
 */
class PathInfoActionParamFilter extends phpinchains_Filter {

    var $cut;
    var $config;

    function init (& $config) 
    {
        $this->cut = $config['module'];
        $this->config = $config;
    }

    function doFilter (& $env, & $chain) 
    {
        $run = phpinchains_RuntimeConfig::getInstance();
        $path_info = $env->getServer('PATH_INFO');
        if ($this->cut)
        {
            $run->set('moduleParam', substr($this->cut, 1));
            $path_info = substr($path_info, strlen($this->cut));
        }
        if (isset($this->config['action']))
        {
            $env->setZombie('__actionParam__',    $this->config['action']);
        }
        else
        {
            $env->setZombie('__actionParam__', substr($path_info, 1));
        }
        if (isset($this->config['parameters']))
        {
            $env->setZombie('__parameterParam__', $this->config['parameters']);
            $run->set("parameterParam", "pathInfo");
        }
        if (isset($this->config['medium']))
        {
            $env->setZombie('__mediumParam__', $this->config['medium']);
        }
        $run->set("actionParam", "pathInfo");
        $chain->doFilter($env);
    } 

}

?>